package com.netcracker.util.service;

import com.netcracker.db.exception.DBException;
import com.netcracker.entity.Country;
import com.netcracker.util.dao.DAOFacade;
import com.netcracker.util.service.exception.DataTransmittingException;
import com.netcracker.util.service.exception.NullDataException;
import java.util.List;

public class CountryService {
        
    private DAOFacade daoFacade;
    
    public CountryService(DAOFacade daoFacade) {
        this.daoFacade = daoFacade;
    }
    
    public void setDAOFacade(DAOFacade daoFacade) {
        this.daoFacade = daoFacade;
    }
    
    public List<Country> getAllCountries() throws DataTransmittingException, NullDataException {
        try {
            List<Country> countrys = daoFacade.getCountryDAO().findAll();
            if (countrys == null) 
                throw new NullDataException("There are no countries.");
            return countrys;
        } catch(DBException ex) {
            throw new DataTransmittingException(ex.getMessage(), ex);
        }
    }
    
}
